package com.mall.controller;

import com.mall.dto.ActionResult;
import com.mall.po.Returnlist;
import com.mall.service.ReturnlistService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName ReturnlistController
 * @Description TODO
 * @action luoliang
 * @Data 2021/1/6 16:12
 * @Version 1.0
 */
@Api(tags = "退货单列表")
@RestController
@RequestMapping("/shangcheng")
public class ReturnlistController {

    @Autowired
    private ReturnlistService returnlistService;

    /**
     * 添加
     * @param record
     * @return
     */
    @ApiOperation(value = "批量添加商品信息")
    @ApiImplicitParam(name = "record",value = "添加一个退货商品）",required = true)
    @RequestMapping(value = "/returnadd",method = RequestMethod.POST)
    public ActionResult AddReturnlist(@RequestBody Returnlist record){
        int i = returnlistService.insertInvoice(record);

        if (i > 0){

            ActionResult success = new ActionResult(200, "success", i);
            return success;
        }else{
            ActionResult success = new ActionResult(500, "error", null);
            return success;
        }

    }

    /**
     * 通过ID删除
     * @param deliverid
     * @return
     */
    @ApiOperation(value = "删除一个商品信息")
    @ApiImplicitParam(name = "deliverids",value = "删除一个商品）",required = true)
    @RequestMapping(value = "/returndel",method = RequestMethod.DELETE)
    public ActionResult delectReturn( Integer deliverid){
        int i = returnlistService.deleteByid(deliverid);

        if (i >-1){
            ActionResult success = new ActionResult(200, "success", i);
            return success;
        }else{
            ActionResult success = new ActionResult(500, "error", i);
            return success;
        }
    }

    /**
     * 修改
     * @param record
     * @return
     */
    @ApiOperation(value = "修改商品信息")
    @ApiImplicitParam(name = "record",value = "修改一个商品）",required = true)
    @RequestMapping(value = "/returnupdate",method = RequestMethod.PUT)
    public  ActionResult UpdateReturn(@RequestBody Returnlist record){

        System.out.println("record="+record);
        int i = returnlistService.updateByInvoice(record);
        if (i > -1){
            ActionResult success = new ActionResult(200, "success", i);
            return success;
        }else{
            ActionResult success = new ActionResult(500, "error", null);
            return success;
        }
    }

    /**
     * 通过ID查询
     * @param deliverid
     * @return
     */
    @ApiOperation(value = "查询一个商品信息")
    @ApiImplicitParam(name = "deliverids",value = "查询一个商品）",required = true)
    @RequestMapping(value = "/deliverquery",method = RequestMethod.GET)
    public ActionResult SelectReturn(Integer deliverid){

        System.out.println("deliverid="+deliverid);
        Returnlist returnlist = returnlistService.selectByid(deliverid);

        if (returnlist != null){
            ActionResult success = new ActionResult(200, "success", returnlist);
            return success;
        }else {
            ActionResult error = new ActionResult(500, "error", null);
            return error;
        }
    }
    /**
     * 批量删除
     * @param deliverids
     * @return
     */
    @ApiOperation(value = "批量删除商品信息")
    @ApiImplicitParam(name = "deliverids",value = "批量删除一个商品）",required = true)
    @RequestMapping(value = "/selectReturnids",method = RequestMethod.DELETE)

    public ActionResult DelectReturnByids( Integer[] deliverids){

        boolean b = returnlistService.delectReturnByids(deliverids);


        ActionResult success = new ActionResult(200, "success", b);
        return success;
    }

    /**
     * 查询分页
     * @param page
     * @param pagesize
     * @return
     */
    @ApiOperation(value = "分页获取退货商品信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "查询的页码",required = true ),
            @ApiImplicitParam(name = "pagesize",value = "每一页包含数据条数",required = true)
    })
    @RequestMapping(value = "/selectReturnPage",method = RequestMethod.GET)
    public List<Returnlist> SelectReturnPage(int page, int pagesize){

        List<Returnlist> returnlists = returnlistService.selectReturnPage(page, pagesize);

        return returnlists;
    }
}
